//
//  ViewController.m
//  test
//
//  Created by Vincent on 2017/3/25.
//  Copyright © 2017年 Vincent. All rights reserved.
//

#import "ViewController.h"
#import "NSNotificationCenter+zll.h"




@interface ViewController ()<CALayerDelegate>



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    NSArray *tmarr = @[@"创建通知",@"发送通知",@"销毁通知"];
    
    CGFloat blank = 20;
    CGFloat btnW = (self.view.frame.size.width-blank*(tmarr.count-1))/tmarr.count;;
    for(int i=0;i<tmarr.count;i++){
        
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((btnW+blank)*i, 100,btnW, 40)];
        btn.backgroundColor = [UIColor redColor];
        btn.tag = 100+i;
        btn.showsTouchWhenHighlighted = YES;
        [btn setTitle:tmarr[i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(destory:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    
}


-(void)destory:(UIButton *)btn{
    
    NSString *ntNam = @"23";
    if(btn.tag==100){
        [NSNotificationCenter addObserverForName:ntNam object:nil usingBlock:^(NSNotification *note) {
            
            NSLog(@"---->%@",note);
            
        }];
    }
    else if(btn.tag==101){
        [[NSNotificationCenter defaultCenter] postNotificationName:ntNam object:@(arc4random()) userInfo:nil];
    }
    else if(btn.tag==102){
        [NSNotificationCenter removeObserveByName:ntNam object:nil];
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
